package org.thread.test02.way04;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author ZQX
 * @date 2025-03-10
 */
public class MainTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 第二：工具类 Executors 创建线程池并返回 ExecutorService 对象
        ExecutorService executorService =
                Executors.newFixedThreadPool(10) ;

        // 第三：创建 Future 对象
        // executorService.submit(Callable对象 | Runnable对象);
        Future<String> future = executorService
                .submit(new MyCallable());

        // 第四：获取值 - 主线程进行阻塞状态
        String msg = future.get();
        System.out.println(msg);

        System.out.println("主线程的一些处理...");

        // 第五：停止服务：
        executorService.shutdownNow() ;

    }
}
